// 提交链接：https://leetcode.cn/problems/left-and-right-sum-differences/description/
// lc2574. 左右元素和的差值
// 完成日期：2024/11/18
// c++ 前缀和 数组

class Solution {
public:
    vector<int> leftRightDifference(vector<int>& nums) {
        int left = 0, right = accumulate(nums.begin(),nums.end(),0);    
        int n = nums.size();
        vector<int> ans;
        for(int i = 0; i < n; ++i)
        {
            right -= nums[i];
            ans.push_back(abs(left - right));
            left += nums[i];
        }
        return ans;
    }
};